package com.suse.warmstill.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.entity.TbRole;
import com.suse.warmstill.mapper.TbMenuMapper;
import com.suse.warmstill.mapper.TbRoleMapper;
import com.suse.warmstill.vo.ConditionVO;
import com.suse.warmstill.vo.MenuOption;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author 黄靖
 * @author 2022-11-03 12:52
 * description:
 **/
@Api(tags = "数据字典,菜单，角色")
@RestController
@RequestMapping("")
public class PCDataApi {

    @Resource
    private TbRoleMapper roleMapper;

    @Resource
    private TbMenuMapper menuMapper;

    @Resource
    private PCMenuApi menuApi;

    @ApiOperation("获取菜单的数据字典")
    @GetMapping("/menuMap")
    public CallResult<List<MenuOption>> getMenuMap() {

        final ConditionVO conditionVO = new ConditionVO();
        conditionVO.setCurrent(1L);
        conditionVO.setSize(100L);
        return menuApi.listMenuOption(conditionVO);

    }


    @ApiOperation("获取角色的数据字典")
    @GetMapping("/roleMap")
    public CallResult<HashMap<Long, String>> getRoleMap() {

        final HashMap<Long, String> roleMap = new HashMap<>();

        final List<TbRole> tbRoles = roleMapper.selectList(new LambdaQueryWrapper<TbRole>());

        tbRoles.forEach((role) -> {
            roleMap.put(role.getId(), role.getRoleName());
        });

        return CallResult.success(roleMap);
    }


}
